package com.northming.daytodo.controller.statisics;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.northming.daytodo.conts.StatusConts;
import com.northming.daytodo.domain.statistics.Stcs;
import com.northming.daytodo.domain.statistics.StcsChart;
import com.northming.daytodo.mapper.statistics.StatisticsMapper;
import com.northming.daytodo.model.UserInfo;
import com.northming.daytodo.util.TimeUtil;
import com.northming.daytodo.util.UserUtil;
import com.northming.daytodo.util.mail.MailService;

@RestController
@RequestMapping("/statistics")
public class StatisticsController {
	
	@Autowired
	private MailService mailService;
	
	
		
	@Autowired
	private UserUtil userUtil;
	
	@Autowired
	private StatisticsMapper statisticsMapper;
	
	@RequestMapping("/testSendMail")
	public boolean testSendMail(){
	
		mailService.sendSimpleMail("535650957@qq.com", "test", "just for test");
		return true;
	}
	
	@RequestMapping("/getThisWeekStcsCharts")
	public Object getThisWeekStcsCharts(){
		String[] thisWeekDays = TimeUtil.getThisWeekDays();
		int len = thisWeekDays.length;
		List<StcsChart> dayStcsCharts = statisticsMapper.getDayStcsCharts(thisWeekDays[0], thisWeekDays[len-1], userUtil.getUserId(),StatusConts.USE);
		StcsChart[] chartArray  = new StcsChart[7];
		for (int i = 0; i < thisWeekDays.length; i++) {
			boolean flag  = false;
			for (int j = 0; j < dayStcsCharts.size(); j++) {
				if(thisWeekDays[i].equals(dayStcsCharts.get(j).getTime())){
					flag =true;
					chartArray[i] = dayStcsCharts.get(j);
					break;
				}
			}
			if(!flag){
				StcsChart stcsChart = new StcsChart();
				stcsChart.setTime(thisWeekDays[i]);
				chartArray[i] = stcsChart;
			}
		}
		//TODO
		return chartArray;
	}
	
	@RequestMapping("/getStcsCharts")
	public List<StcsChart> getStcsChart(){
		
		return null;
	}

	@RequestMapping("/getStcs")
	public List<Stcs> getStcs(String startDate,String endDate,String timeType){
		
		return null;
	}
	
	
}
